package com.ruoyi.food.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.food.object.TActOrder;
import com.ruoyi.food.object.TEnterprise;
import com.ruoyi.food.object.TUser;
import com.ruoyi.food.service.TActOrderService;
import com.ruoyi.food.service.TEnterpriseService;
import com.ruoyi.food.service.TUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 活动订单controller
 * 
 * @author mengcc
 *
 */
@Controller
@Api(value = "TActOrderController", tags = "活动订单controller")
@RequestMapping("/order")
public class TActOrderController extends BaseController {

	@Autowired
	private TActOrderService tActOrderService;

	@Autowired
	private TUserService tUserService;
	
	@Autowired
	private TEnterpriseService tEnterpriseService;

	/**
	 * 进入活动订单页面
	 * 
	 * @return
	 */
	@GetMapping()
	public String order() {
		return "page/order";
	}

	/**
	 * 查询活动订单
	 * 
	 * @param tActOrder
	 * @return
	 */
	@PostMapping("/list")
	@ApiOperation("查询订单列表")
	@ResponseBody
	public TableDataInfo findTActOrder(TActOrder tActOrder) {

		startPage();
		List<TActOrder> list = new ArrayList<>();

		list = tActOrderService.findTActOrderByCon(tActOrder);

		return getDataTable(list);
	}
	
	/**
	 * 进入一元购水活动订单界面
	 * @return
	 */
	@GetMapping("/water")
	public String waterOrder() {
		return "page/order/waterOrder";
	}
	
	@PostMapping("/listByOne")
	@ApiOperation("查询一元购水的订单列表")
	@ResponseBody
	public TableDataInfo findTActOrderByOne(TActOrder tActOrder) {
		startPage();
		List<TActOrder> list = new ArrayList<>();

		List<Long> actIds=new ArrayList<>();
		actIds.add(new Long(1));
		actIds.add(new Long(2));
		list = tActOrderService.findTActOrderByActId(actIds, tActOrder);

		return getDataTable(list);
	}
	
	@GetMapping("/wadamao")
	public String wadamaoOrder() {
		return "page/order/wadamaoOrder";
	}
	
	@PostMapping("/listByWadamao")
	@ApiOperation("查询万达茂的订单列表")
	@ResponseBody
	public TableDataInfo findTActOrderByWaDaMao(TActOrder tActOrder) {
		startPage();
		List<TActOrder> list = new ArrayList<>();

		List<Long> actIds=new ArrayList<>();
		actIds.add(new Long(3));
		actIds.add(new Long(4));
		list = tActOrderService.findTActOrderByActId(actIds, tActOrder);

		return getDataTable(list);
	}

	//@PostMapping("/listByMobile")
	@GetMapping("/listByMobile")
	@ApiOperation("通过用户电话查询活动订单列表")
	@ApiImplicitParam(name = "mobile", value = "用户电话号码", dataType = "String")
	@ResponseBody
	public List<TActOrder> findTActOrderByUserMobile(String mobile,long enterpriseId) {
		/*TUser tUser = tUserService.findUserByMobile(mobile);
		List<TActOrder> tActOrders=tActOrderService.findTActOrderByClientId(tUser.getUserId());*/
		List<TActOrder> tActOrders=tActOrderService.findTActOrderByMobile(mobile);
		TEnterprise tEnterprise=tEnterpriseService.findTenterpriseById(enterpriseId);
		for(TActOrder tActOrder:tActOrders) {
			tActOrder.setStockNum(tEnterprise.getStockNum());
		}
		
		return tActOrders;

	}

}
